#include <unistd.h>
#include <sys/select.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>

int main()
{
    fd_set fds;
    fd_set fdsout;


    FD_ZERO(&fds);
    FD_ZERO(&fdsout);
    FD_SET(0,&fds);
    FD_SET(1,&fdsout);

    int r;
    char buff[1024];
    while (1)
    {
        r = select(2,&fds,&fdsout,NULL,NULL);

        if (r>0)
        {
            printf("继续监视\n");
            if (FD_ISSET(0,&fds))
            {
                printf("是0有动静\n");

                printf("处理\n");

                scanf("%s",buff);
                printf("%s\n",buff);
                //清空
                 //FD_CLR(0,&fds);
            }
            if (FD_ISSET(0,&fdsout))
            {
                printf("输出有动静------\n");

                FD_CLR(0,&fdsout);


            }
        }else if (r==0)
        {
            printf("没有动静\n");
        }else
        {
            printf("错误:%m\n");
        }
    }

    return 0;
}
